package com.efounder.frame.utils;

import android.os.Environment;

import com.efounder.constant.EnvironmentVariable;
import com.efounder.util.AppContext;

import java.io.File;

public class EFConstants {

    /**
     * 外部存储的根目录, 一般是 /sdcard
     */
    private static String sdDir = null;

    static {
        //判断sd卡是否可用
        boolean isSdCardEnable = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
        if (isSdCardEnable) {
            sdDir = Environment.getExternalStorageDirectory().getAbsolutePath();//获取跟目录
        } else {
            sdDir = Environment.getRootDirectory().getAbsolutePath();
        }

        if (EnvironmentVariable.getProperty("supportPartStorage", "0").equals("1")) {
            //androidq以上启用了分区存储功能
            sdDir = AppContext.getInstance().getExternalFilesDir(null).getAbsolutePath();

        }
    }

    /**
     * 存储根目录
     */
    public static final String EXTERNAL_ROOT = sdDir;

    /**
     * 应用程序根目录
     */
    public static final String APP_ROOT = EXTERNAL_ROOT + File.separator + EnvironmentVariable.getProperty("APPID", "");

    static {
        File rootDir = new File(APP_ROOT);
        if (!rootDir.exists()) {
            rootDir.mkdirs();
        }
    }

    //资源文件所在的根路径, zip文件下载到该目录
    public static final String DOWN_LOAD = APP_ROOT + "/download";

    //public static final String RES_DIR = Environment.getExternalStorageDirectory()+"/ESPMobile/res";
    public static final String RES_DIR = APP_ROOT + "/res";

    //zip文件解压到的资源目录
    public static final String UNZIP_DIR = RES_DIR + "/" + "unzip_res";

    //图片所在目录
    public static final String IMAGE_DIR = UNZIP_DIR + "/" + "Image";

    //表单所在路径
    public static final String FORM_DIR = UNZIP_DIR + "/" + "Form";

    //菜单所在路径
    public static final String PACKAGE_DIR = UNZIP_DIR + "/" + "Package";

    /****/
    public static final String APPS_DIR = UNZIP_DIR + "/" + "Apps";


    //更新时将update.zip解压到临时目录
    public static final String UNZIP_TEMP_DIR = RES_DIR + "/" + "unzip_temp";

    //临时图片目录
    public static final String TEMP_IMAGE_DIR = UNZIP_TEMP_DIR + "/" + "Image";

    //临时菜单目录
    public static final String TEMP_PACKAGE_DIR = UNZIP_TEMP_DIR + "/" + "Package";

    //临时表单目录
    public static final String TEMP_FORM_DIR = UNZIP_TEMP_DIR + "/" + "Form";
}
